
var picasaConnect;
  
PicasaConnector.prototype = {};

function PicasaConnector()
{
	this.isPicasaRequest = PicasaConnector_isPicasaRequest;
	this.transformPicasaResult = PicasaConnector_transformPicasaResult;
}

function PicasaConnector_isPicasaRequest(requestString)
{
	return (requestString && requestString.indexOf("picasaweb.google")>-1);
}

function PicasaConnector_transformPicasaResult(jsonData)
{
	var jsonOut = [];
	if (jsonData && jsonData.feed && jsonData.feed.entry)
	{
		var listePhotos = jsonData.feed.entry;		
		for (var i=0;i<listePhotos.length;i++)
		{
			var photo = {};
			//photo.unique_id = attributesList.id;
			//photo.object_id = attributesList.object_id;
			//photo.parent = attributesList.parent;
			photo.object_type = "PicasaPhoto";
			//photo.deleted = 0;
			photo.order_rank = i;
			//photo.deleted_at = attributesList.deleted_at;
			//photo.created_at = attributesList.created_at;
			var attributesList = [];
			attributesList.push({"name": "title", "data_value": listePhotos[i].title.$t, "data_type": "Text"});
			attributesList.push({"name": "filename", "data_value": listePhotos[i].media$group.media$title.$t, "data_type": "Text"});
			attributesList.push({"name": "urlImage", "data_value": listePhotos[i].content.src, "data_type": "Text"});
			attributesList.push({"name": "widthImage", "data_value": listePhotos[i].media$group.media$content[0].width, "data_type": "Text"});
			attributesList.push({"name": "heightImage", "data_value": listePhotos[i].media$group.media$content[0].height, "data_type": "Text"});
			attributesList.push({"name": "auteur", "data_value": listePhotos[i].media$group.media$credit[0].$t, "data_type": "Text"});
			attributesList.push({"name": "idPicasa", "data_value": listePhotos[i].id.$t, "data_type": "Text"});
			attributesList.push({"name": "published", "data_value": listePhotos[i].published.$t, "data_type": "Text"});
			
			attributesList.push({"name": "urlMini1", "data_value": listePhotos[i].media$group.media$thumbnail[0].url, "data_type": "Text"});
			attributesList.push({"name": "mini1Height", "data_value": listePhotos[i].media$group.media$thumbnail[0].height, "data_type": "Text"});
			attributesList.push({"name": "mini1Width", "data_value": listePhotos[i].media$group.media$thumbnail[0].width, "data_type": "Text"});
			
			attributesList.push({"name": "urlMini2", "data_value": listePhotos[i].media$group.media$thumbnail[1].url, "data_type": "Text"});
			attributesList.push({"name": "mini2Height", "data_value": listePhotos[i].media$group.media$thumbnail[1].height, "data_type": "Text"});
			attributesList.push({"name": "mini2Width", "data_value": listePhotos[i].media$group.media$thumbnail[1].width, "data_type": "Text"});
			
			attributesList.push({"name": "urlMini3", "data_value": listePhotos[i].media$group.media$thumbnail[2].url, "data_type": "Text"});
			attributesList.push({"name": "mini3Height", "data_value": listePhotos[i].media$group.media$thumbnail[2].height, "data_type": "Text"});
			attributesList.push({"name": "mini3Width", "data_value": listePhotos[i].media$group.media$thumbnail[2].width, "data_type": "Text"});

			photo.attributes = attributesList;
			
			jsonOut.push(photo);
		}
	}
	var retour = {};
	retour.result = jsonOut
	return retour;
}

picasaConnect = new PicasaConnector();
